<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        a {
            text-decoration: none;
            color: inherit;
        }

        li {
            list-style: none;
        }

        img {
            vertical-align: top;
        }

        #showGoods {
            width: 1226px;
            margin: 0 auto;
            margin-top: 50px;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
        }

        #showGoods li {
            width: 18%;
            box-sizing: border-box;
            padding: 10px;
            font-size: 13px;
            line-height: 20px;
        }

        #showGoods li:hover {
            box-shadow: 0 0 1px 2px rgba(0, 0, 0, 0.2);
        }

        #showGoods li img {
            width: 70%;
            display: block;
            margin: 20px auto;
        }

        #showGoods li .price {
            color: red;
        }

        #showGoods li .name {
            /* 多行文本溢出隐藏 */
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <ul id="showGoods">
        <!-- <li>
            <a href="">
                <img src="https://img12.360buyimg.com/n7/jfs/t1/195641/2/30490/89452/63745247Efb2a8608/46028f28c82c3faf.jpg"
                    alt="">
                <div class="price">6499.00</div>
                <div class="name">华为（HUAWEI） 笔记本电脑MateBook D16 16英寸高性能轻薄本商务办公学生手提超极本 银丨十二代i5-12500H 16G 512G</div>
                <div class="comment">2000+条评价</div>
                <div class="shop">华为比特专卖店</div>
            </a>
        </li>
        <li>
            <a href="">
                <img src="https://img12.360buyimg.com/n7/jfs/t1/195641/2/30490/89452/63745247Efb2a8608/46028f28c82c3faf.jpg"
                    alt="">
                <div class="price">6499.00</div>
                <div class="name">华为（HUAWEI） 笔记本电脑MateBook D16 16英寸高性能轻薄本商务办公学生手提超极本 银丨十二代i5-12500H 16G 512G</div>
                <div class="comment">2000+条评价</div>
                <div class="shop">华为比特专卖店</div>
            </a>
        </li>
        <li>
            <a href="">
                <img src="https://img12.360buyimg.com/n7/jfs/t1/195641/2/30490/89452/63745247Efb2a8608/46028f28c82c3faf.jpg"
                    alt="">
                <div class="price">6499.00</div>
                <div class="name">华为（HUAWEI） 笔记本电脑MateBook D16 16英寸高性能轻薄本商务办公学生手提超极本 银丨十二代i5-12500H 16G 512G</div>
                <div class="comment">2000+条评价</div>
                <div class="shop">华为比特专卖店</div>
            </a>
        </li>
        <li>
            <a href="">
                <img src="https://img12.360buyimg.com/n7/jfs/t1/195641/2/30490/89452/63745247Efb2a8608/46028f28c82c3faf.jpg"
                    alt="">
                <div class="price">6499.00</div>
                <div class="name">华为（HUAWEI） 笔记本电脑MateBook D16 16英寸高性能轻薄本商务办公学生手提超极本 银丨十二代i5-12500H 16G 512G</div>
                <div class="comment">2000+条评价</div>
                <div class="shop">华为比特专卖店</div>
            </a>
        </li>
        <li>
            <a href="">
                <img src="https://img12.360buyimg.com/n7/jfs/t1/195641/2/30490/89452/63745247Efb2a8608/46028f28c82c3faf.jpg"
                    alt="">
                <div class="price">6499.00</div>
                <div class="name">华为（HUAWEI） 笔记本电脑MateBook D16 16英寸高性能轻薄本商务办公学生手提超极本 银丨十二代i5-12500H 16G 512G</div>
                <div class="comment">2000+条评价</div>
                <div class="shop">华为比特专卖店</div>
            </a>
        </li>
        <li>
            <a href="">
                <img src="https://img12.360buyimg.com/n7/jfs/t1/195641/2/30490/89452/63745247Efb2a8608/46028f28c82c3faf.jpg"
                    alt="">
                <div class="price">6499.00</div>
                <div class="name">华为（HUAWEI） 笔记本电脑MateBook D16 16英寸高性能轻薄本商务办公学生手提超极本 银丨十二代i5-12500H 16G 512G</div>
                <div class="comment">2000+条评价</div>
                <div class="shop">华为比特专卖店</div>
            </a>
        </li> -->
    </ul>
</body>
<script>
    var data = {
        "code": 200,
        "message": "OK",
        "list": [
            {
                "goodsId": "A001",
                "goodsName": "华为（HUAWEI） 笔记本电脑MateBook D16 16英寸高性能轻薄本商务办公学生手提超极本 银丨十二代i5-12500H 16G 512G",
                "goodsImg": "https://img12.360buyimg.com/n7/jfs/t1/195641/2/30490/89452/63745247Efb2a8608/46028f28c82c3faf.jpg",
                "goodsPrice": "5699.00",
                "commentCount": "2000+条评价",
                "shopName": "华为比特专卖店"
            },
            {
                "goodsId": "A002",
                "goodsName": "HUAWEI nova 8 SE 6400万高清四摄 支持66W超级快充 6.5英寸OLED大屏 8GB+128GB幻夜黑华为手机 标配无充",
                "goodsImg": "https://img11.360buyimg.com/n7/jfs/t1/172154/14/29890/38175/634d43e2E4b955033/0fd37f341d1a6186.jpg",
                "goodsPrice": "1199.00",
                "commentCount": "20万+条评价",
                "shopName": "华为京东自营官方旗舰店"
            },
            {
                "goodsId": "A003",
                "goodsName": "HUAWEI Mate 50 直屏旗舰 超光变XMAGE影像 北斗卫星消息 低电量应急模式 128GB曜金黑华为鸿蒙手机",
                "goodsImg": "https://img11.360buyimg.com/n7/jfs/t1/161463/36/32570/66358/636e661cE6ed2922d/cbcdc33ce6d66663.jpg",
                "goodsPrice": "4999.00",
                "commentCount": "2万+条评价",
                "shopName": "华为京东自营官方旗舰店"
            },
            {
                "goodsId": "A004",
                "goodsName": "华为（HUAWEI） 华为电视智慧屏86英寸 HarmonyOS 3 超大屏4K超高清液晶教育电视机 华为智慧屏S86 Pro(有摄像头)4+64G",
                "goodsImg": "https://img13.360buyimg.com/n7/jfs/t1/129886/38/33358/135433/6373051aEc175bf8b/3e56b288862216dc.jpg",
                "goodsPrice": "11999.00",
                "commentCount": "87+条评价",
                "shopName": "京东电器旗舰"
            },
            {
                "goodsId": "A005",
                "goodsName": "HUAWEI Pocket S 折叠屏手机 时尚多彩 40万次折叠认证 后摄人像自拍 256GB 冰霜银 华为小折叠pockets",
                "goodsImg": "https://img10.360buyimg.com/n7/jfs/t1/180779/4/30342/52096/6371f1d6E27b5cf53/59d4f937821167c0.jpg",
                "goodsPrice": "6488.00",
                "commentCount": "2000+条评价",
                "shopName": "京东电器旗舰"
            }
        ]
    }

    // 动态生成之前先写静态页面 

    var showGoods = document.getElementById("showGoods");

    var list = data.list; // 取出商品数据
    var html = "";
    list.forEach(function (item) {

        var goodsName = item.goodsName;
        var goodsImg = item.goodsImg;
        var goodsPrice = item.goodsPrice;
        var commentCount = item.commentCount;
        var shopName = item.shopName;
        html += `<li>
            <a href="">
                <img src="${goodsImg}"
                    alt="">
                <div class="price">${goodsPrice}</div>
                <div class="name">${goodsName}</div>
                <div class="comment">${commentCount}</div>
                <div class="shop">${shopName}</div>
            </a>
        </li>`;
    });

    showGoods.innerHTML = html;
</script>

</html>